package com.lagou.ipersistence.type;

import java.sql.Types;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Yan Jiahong
 * Created on 2020/11/17
 */
public enum JdbcType {
    VARCHAR(Types.VARCHAR),
    INT(Types.INTEGER),
    BIGINT(Types.BIGINT),
    DATE(Types.DATE),
    OTHER(Types.OTHER),
    
    ;
    
    public final int typeCode;
    
    private static Map<Integer, JdbcType> codeMap = new HashMap<>();
    
    static {
        for (JdbcType type : JdbcType.values()) {
            codeMap.put(type.typeCode, type);
        }
    }
    
    JdbcType(int typeCode) {
        this.typeCode = typeCode;
    }
    
    public static JdbcType forCode(int code) {
        return codeMap.get(code);
    }
}
